// pages/mine/mine.js
var api = require('../../../app/app.js')
Page({

  /**
   * 页面的初始数据
   */
  data: {
    nothing: 'https://www.sdhjfu.com/smallhouse/public/house/images/no.jpg',
    dayu: 'https://www.sdhjfu.com/smallhouse/public/tianxing/images/dayu.jpg',
    showPage: true,
    me_code: 'https://www.sdhjfu.com/smallhouse/public/house/images/me_code.jpg',
    me_contact: 'https://www.sdhjfu.com/smallhouse/public/house/images/me_contact.jpg',
    me_idea: 'https://www.sdhjfu.com/smallhouse/public/house/images/me_idea.jpg',
    me_edition: 'https://www.sdhjfu.com/smallhouse/public/house/images/me_edition.jpg',
    me_quit: 'https://www.sdhjfu.com/smallhouse/public/house/images/me_quit.jpg',
    phone: '',
    integralMe: '',
    recommendMe: '',
    name: '',
    avatar: ''
  },
  /**
   * 生命周期函数--监听页面加载
   */
  onLoad: function (options) {
    wx.setNavigationBarTitle({
      title: '个人中心'
    })
  },
  butLogin: function () {
    wx.showModal({
      title: '您还未登陆',
      content: '请先登录再进行操作',
      success(res) {
        if (res.confirm) {
          //console.log('用户点击确定')
          wx.redirectTo({
            url: '/pages/authorization/authorization'
          })
        } else if (res.cancel) {
          //console.log('用户点击取消')
        }
      }
    })
  },
  codeClick: function() { // 跳转兑换码页面
    wx.navigateTo({
      url: '../components/code/code',
    })
  },
  contactClick: function () { // 跳转联系客服页面
    wx.makePhoneCall({
      phoneNumber: '0543-4868777',
    })
  },
  ideaClick: function () { // 跳转意见反馈页面
    wx.navigateTo({
      url: '../components/idea/idea',
    })
  },
  editionClick() { // 跳转版本页面
    wx.navigateTo({
      url: '../components/edition/edition',
    })
  },
  quitClick: function () { // 退出页面 // wx.checkSession可以判断是否登录已过期
    wx.showModal({
      title: '退出',
      content: '您确定要退出当前账号吗',
      success(res) {
        if (res.confirm) {
          // 清空缓存
          // wx.clearStorage()
          wx.reLaunch({
            url: "../../load/login/login"
          })
        } else if (res.cancel) {
        }
      }
    })
   
  },
  integralClick: function() { // 跳转积分页面
    wx.navigateTo({
      url: '../components/integral/integral',
    })
  },
  recommendClick:function() { // 跳转我的推荐页面
    wx.navigateTo({
      url: '../components/recommend/recommend',
    })
  },
  /**
   * 生命周期函数--监听页面初次渲染完成
   */
  onReady: function () {
    
  },

  /**
   * 生命周期函数--监听页面显示
   */
  onShow: function () {
    var that = this
    wx.getStorage({ // 获取本地缓存
      key: 'userReInfo',
      success(res) {
        // console.log(res.data)
        var userId = res.data.userId
        that.setData({
          phone: res.data.phone,
          avatar: res.data.avatarUrl,
          name: res.data.nickName
        })
        if (!that.data.phone) {
          that.setData({
            showPage: true
          })
        } else {
          that.setData({
            showPage: false
          })
        }
        // 获取商品的信息
        wx.request({
          url: api.Userdatacount,
          method: 'POST',
          data: {
            userId: userId
          },
          header: {
            'content-Type': 'application/x-www-form-urlencoded' // post请求头
          },
          success: function (res) {
           // console.log(res.data)
            that.setData({
              integralMe: res.data.intercount,
              recommendMe: res.data.tnotecount
            })
          }
        })
      }
    })
  },

  /**
   * 生命周期函数--监听页面隐藏
   */
  onHide: function () {
    
  },

  /**
   * 生命周期函数--监听页面卸载
   */
  onUnload: function () {
    
  },

  /**
   * 页面相关事件处理函数--监听用户下拉动作
   */
  onPullDownRefresh: function () {
    
  },

  /**
   * 页面上拉触底事件的处理函数
   */
  onReachBottom: function () {
    
  },

  /**
   * 用户点击右上角分享
   */
  onShareAppMessage: function () {
    
  }
})
